package com.cao.controller;


import com.cao.entity.Gird;
import com.cao.entity.Test;
import com.cao.mapper.GirdMapper;
import com.cao.service.GirdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author EN
 * @since 2021-08-26
 */
@Controller
@RequestMapping("gird.do")
public class GirdController {

    @Autowired
    private GirdMapper girdMapper;

    @RequestMapping(params = "mathod=all")
    @ResponseBody
    public List<Gird> all() {

        InetAddress myhost=null;
        try {
            myhost=InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        //得到被服务器的地址
        String xpath=myhost.getHostAddress();

        List<Gird> testList= girdMapper.selectList(null);

        for (Gird tt:testList
        ) {
            //拼接地址
            tt.setGimg("http://"+xpath+":9000/"+tt.getGimg());
            //System.out.println(tt.getGimg());
        }
        return testList;
    }

}

